/*
 * 类名称:FireExtinguisherController.java
 * 包名称:com.platform.controller
 *
 * 修改履历:
 *     日期                       修正者        主要内容
 *     2019-09-25 19:51:14        hww     初版做成
 *
 * Copyright (c) 2019-2019 微同科技
 */
package com.platform.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.platform.annotation.IgnoreAuth;
import com.platform.annotation.SysLog;
import com.platform.entity.SysUserEntity;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import com.platform.controller.AbstractController;
import com.platform.entity.FireExtinguisherEntity;
import com.platform.service.FireExtinguisherService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * 灭火器Controller
 *
 * @author hww
 * @date 2019-09-25 19:51:14
 */
@RestController
@RequestMapping("fs/fireextinguisher")
public class FireExtinguisherController extends AbstractController {
    @Autowired
    private FireExtinguisherService fireExtinguisherService;

    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return R
     */
    @RequestMapping("/queryAll")
    @IgnoreAuth
    @RequiresPermissions("fs:fireextinguisher:list")
    public R queryAll(@RequestParam Map<String, Object> params) {
        List<FireExtinguisherEntity> list = fireExtinguisherService.queryAll(params);

        return R.ok().put("list", list);
    }

    /**
     * 分页查询灭火器
     *
     * @param params 查询参数
     * @return R
     */
    @GetMapping("/list")
    @IgnoreAuth
//    @RequiresPermissions("fs:fireextinguisher:list")
    public R list(@RequestParam Map<String, Object> params) {



        Page page = fireExtinguisherService.queryPage(params);

        List<FireExtinguisherEntity> list = page.getRecords();
        //值转换
        for (FireExtinguisherEntity fireExtinguisherEntity : list) {
            String status = fireExtinguisherEntity.getStatus();
            String statusName = "0".equals(status)?"否":"是";
            fireExtinguisherEntity.setStatusName(statusName);
        }
        int total = (int)page.getTotal();//;
        int pageNum = (int)page.getCurrent();//
        int limit = (int)page.getSize();
        PageUtils pageUtil = new PageUtils(list,total,limit,pageNum);
        return R.ok().put("page", pageUtil);
    }

    /**
     * 根据主键查询详情
     *
     * @param id 主键
     * @return R
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("fs:fireextinguisher:info")
    public R info(@PathVariable("id") String id) {
        FireExtinguisherEntity fireExtinguisher = fireExtinguisherService.getById(id);

        return R.ok().put("fireExtinguisher", fireExtinguisher);
    }

    /**
     * 新增灭火器
     *
     * @param fireExtinguisher fireExtinguisher
     * @return R
     */
    @SysLog("新增灭火器")
    @RequestMapping("/save")
    @IgnoreAuth
    @RequiresPermissions("fs:fireextinguisher:save")
    public R save(@RequestBody FireExtinguisherEntity fireExtinguisher) {
        fireExtinguisher.setId(UUID.randomUUID().toString());
        fireExtinguisher.setCreateTime(new Date());
        fireExtinguisher.setCreateUserName("黄某某");
        fireExtinguisherService.add(fireExtinguisher);

        return R.ok();
    }

    /**
     * 修改灭火器
     *
     * @param fireExtinguisher fireExtinguisher
     * @return R
     */
    @SysLog("修改灭火器")
    @RequestMapping("/update")
//    @RequiresPermissions("fs:fireextinguisher:update")
    public R update(@RequestBody FireExtinguisherEntity fireExtinguisher) {

        fireExtinguisherService.update(fireExtinguisher);

        return R.ok();
    }

    /**
     * 根据主键删除灭火器
     *
     * @param ids ids
     * @return R
     */
    @SysLog("删除灭火器")
    @RequestMapping("/delete")
//    @RequiresPermissions("fs:fireextinguisher:delete")
    public R delete(@RequestBody String[] ids) {
        fireExtinguisherService.deleteBatch(ids);

        return R.ok();
    }
}
